import time
common_user = {'xuesh':['123','打篮球'],'baoan':['234','游泳'],'aidou':['345','吹牛']}
manager = {'root':['123456','呼吸']}

#查看当前用户信息
def check():
    print(f'姓名          密码           爱好')
    for i in common_user:
        print(f'{i}        {common_user[i][0]}          {common_user[i][1]}')

#修改某位用户
def alter():
    hobby = input('请输入要修改的爱好:')
    print('恭喜您修改成功！！！')

#删除某位用户
def delete():
    username1 = input('请输入要删除的用户：')
    if username1 in common_user:
        common_user.pop(username1)
        print('恭喜您删除成功')
    elif username1 in manager:
        print('您无法删除与您同级的用户')
    else:
        print('抱歉您输入的用户名不存在')

#添加某位用户
def add():
    username2 = input('请输入要添加的用户名：')
    passwd2 = input('请输入要添加的密码:')
    hobby2 = input('请输入要添加的爱好:')
    role = input('请输入此用户角色:')
    if role != '管理员':
        if username2 in common_user:
            print('此用户名已被占用，请重新输入用户名:')
        else:
            common_user[username2] = [passwd2,hobby2]
            print('恭喜您已添加成功')
    else:
        if username2 in manager:
            print('此用户名已被占用，请重新输入用户名:')
        else:
            common_user[username2] = [passwd2,hobby2]
            print('恭喜您已添加成功')

#一级菜单
def menu1():
    print('一级菜单:')
    print('一.按1登录'.center(50,'='))
    print('二.按任意退出'.center(50,'='))
    b = int(input('请选择登录或退出:'))
    if b == 1:
        flag2 = 0
        flag3 = 0
        while True:
            username = input('请输入您的用户名:')
            if username not in common_user and username not in manager:
                print('您输入的用户不存在')
            elif username in manager:
                    passwd1 = input('请输入您的密码:')
                    if manager[username][0] != passwd1:
                        flag2 += 1
                        print('您输入的密码有误!')
                        if flag2 == 3:
                            print('您已输错三次，请等5分钟后再尝试')
                            time.sleep(300)
                            menu1()
                    else:
                        print('恭喜您以管理员的身份登录成功，进入二级菜单!\n')
                        menu2()
                        break
            else:
                passwd2 = input('请输入您的密码:')
                if common_user[username][0] != passwd2:
                    flag3 += 1
                    print('您输入的密码有误!')
                    if flag3 == 3:
                        print('您已输错三次，请等5分钟后再尝试')
                        time.sleep(300)
                        menu1()
                else:
                     print('恭喜您已普通用户的身份登录成功\n')
                     print('一.按1添加爱好')
                     print('二.按2返回一级菜单')
                     print('三.按任意键退出')
                     c = int(input('请选择:'))
                     if c == 1:
                        alter()
                        menu1()
                     elif c == 2:
                         menu1()
                     else:
                          print('您已退出')
    else:
        print('您已退出')

#二级菜单
def menu2():
    print('二级菜单功能表：'.center(50,'='))
    print('一.按1查看当前用户信息表')
    print('二.按2修改用户的信息')
    print('三.按3删除用户')
    print('四.按4添加用户')
    print('五.按5返回上一级菜单')
    print('六.按任意键退出')
    while True:
        count = int(input('请输入一个数选择功能:'))
        if count == 1:
            check()
        elif count == 2:
            alter()
        elif count == 3:
            delete()
        elif count == 4:
            add()
        elif count == 5:
            print(menu1())
        else:
            print('您已退出程序')
            break

menu1()

